"""
订单信息查询相关模型

@author liaochangyi
@since 2025-01-25
"""

from typing import Dict, Any
from jlpay.model.base import OrgBaseReq, BaseResponse


class OrderInfoQueryRequest(OrgBaseReq):
    """订单信息查询请求"""

    API_URL = "/open/bill/trans-charge/query"

    def __init__(self):
        """初始化订单信息查询请求"""
        super().__init__()
        self.order_id = None  # 嘉联订单号

    def set_order_id(self, order_id: str):
        """
        设置嘉联订单号

        Args:
            order_id: 嘉联订单号

        Returns:
            OrderInfoQueryRequest实例
        """
        self.order_id = order_id
        return self

    def to_dict(self) -> Dict[str, Any]:
        """转换为字典格式"""
        data = super().to_dict()
        data.update({
            'order_id': self.order_id
        })
        return data


class OrderInfoQueryResponse(BaseResponse):
    """订单信息查询响应"""

    def __init__(self, response_dict=None):
        """
        初始化订单信息查询响应

        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.merch_no = None  # 商户号
        self.term_no = None  # 终端号
        self.out_order_id = None  # 客户订单号
        self.order_id = None  # 嘉联订单号
        self.chn_transaction_id = None  # 渠道订单号，微信、支付宝、银联侧的订单号（码付交易时有）
        self.ori_order_id = None  # 原嘉联订单号（退款交易时有）
        self.trans_time = None  # 交易时间（yyyy-MM-dd HH:mm:ss）
        self.amount = None  # 交易金额（单位为分）
        self.fee_type = None  # 计费类型
        self.card_type = None  # 卡类型，0：借记卡 1：贷记卡 2：余额
        self.trans_fee = None  # 应收手续费，单位为分，收款交易手续费为正值，退款交易手续费为负值，无手续费为0，说明：该手续费为优惠减免前的手续费
        self.finnal_fee = None  # 实收手续费，单位为分，收款交易手续费为正值（优惠减免后手续费）退款交易手续费为负值，无手续费为0，说明：该手续费为优惠减免后的手续费，且以此字段作为该笔订单手续费
        self.sub_openid = None  # 用户身份id（码付交易时有）
        self.remark = None  # 备注产品来源：立牌/电子码牌、银行卡、外接码付、订单POS、智能SDK

        if response_dict:
            self.merch_no = response_dict.get('merch_no')
            self.term_no = response_dict.get('term_no')
            self.out_order_id = response_dict.get('out_order_id')
            self.order_id = response_dict.get('order_id')
            self.chn_transaction_id = response_dict.get('chn_transaction_id')
            self.ori_order_id = response_dict.get('ori_order_id')
            self.trans_time = response_dict.get('trans_time')
            self.amount = response_dict.get('amount')
            self.fee_type = response_dict.get('fee_type')
            self.card_type = response_dict.get('card_type')
            self.trans_fee = response_dict.get('trans_fee')
            self.finnal_fee = response_dict.get('finnal_fee')
            self.sub_openid = response_dict.get('sub_openid')
            self.remark = response_dict.get('remark')

    def to_dict(self) -> Dict[str, Any]:
        """转换为字典格式"""
        data = super().to_dict()
        data.update({
            'merch_no': self.merch_no,
            'term_no': self.term_no,
            'out_order_id': self.out_order_id,
            'order_id': self.order_id,
            'chn_transaction_id': self.chn_transaction_id,
            'ori_order_id': self.ori_order_id,
            'trans_time': self.trans_time,
            'amount': self.amount,
            'fee_type': self.fee_type,
            'card_type': self.card_type,
            'trans_fee': self.trans_fee,
            'finnal_fee': self.finnal_fee,
            'sub_openid': self.sub_openid,
            'remark': self.remark
        })
        return data